<?php

$g = array();
$g['status'] = 0;
if(array_key_exists('gamer', $_REQUEST))
{
	$curl = curl_init();
	curl_setopt($curl, CURLOPT_URL, $_REQUEST['gamer'] . ".gamer.ru/posts");
	curl_setopt($curl, CURLOPT_HEADER, true);
	curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
	curl_setopt($curl, CURLOPT_NOBODY, true);
	$buffer = curl_exec($curl);
	curl_close($curl);

	preg_match("#HTTP/1.1 200 OK#i", $buffer, $matches);
	if(count($matches))
	{
		include 'gamer.php';
		$gamer = new Gamer($_REQUEST['gamer']);
		$g['status'] = 1;
		$g['name'] = $gamer->GetName();
		$g['level'] = $gamer->GetLevel();
		$g['place'] = $gamer->GetPlace();
		$g['diamond'] = $gamer->GetPosts('diamond');
		$g['silver'] = $gamer->GetPosts('silver');
		$g['golden'] = $gamer->GetPosts('golden');
		$g['posts'] = $gamer->GetPosts('default');
		$g['comments'] = $gamer->GetComments();
	}
	else
	{
		$g['status'] = 2;
	}
}
header('Content-type: application/json; charset=utf-8');
echo json_encode($g);

?>